package com.example.demo.entry;

import org.springframework.ldap.core.AttributesMapper;

import javax.naming.NamingException;
import javax.naming.directory.Attributes;

/**
 * 这个类的作用是将ldap中的属性转化为实体类的属性值，
 * 在查询信息的时候会用到
 */
public class OrganizationAttributeMapper implements AttributesMapper {

    public Object mapFromAttributes(Attributes attr) throws NamingException {
        Organization organization = new Organization();
        organization.setOu((String) attr.get("ou").get());
        //organization.setCn((String)attr.get("cn").get());

        if (attr.get("description") != null) {
            organization.setDescription((String) attr.get("description").get());
        }
        if (attr.get("physicalDeliveryOfficeName") != null) {
            organization.setPhysicalDeliveryOfficeName((String) attr.get("seeAlso").get());
        }
        if (attr.get("telephoneNumber") != null) {
            organization.setTelephoneNumber((String) attr.get("telephoneNumber").get());
        }
        if (attr.get("facsimileTelephoneNumber") != null) {
            organization.setFacsimileTelephoneNumber((String) attr.get("facsimileTelephoneNumber").get());
        }
        if (attr.get("street") != null) {
            organization.setStreet((String) attr.get("street").get());
        }
        if (attr.get("postOfficeBox") != null) {
            organization.setPostOfficeBox((String) attr.get("postOfficeBox").get());
        }
        if (attr.get("postalAddress") != null) {
            organization.setPostalAddress((String) attr.get("postalAddress").get());
        }
        if (attr.get("l") != null) {
            organization.setL((String) attr.get("l").get());
        }
        if (attr.get("postalAddress") != null) {
            organization.setPostalAddress((String) attr.get("postalAddress").get());
        }
        if (attr.get("st") != null) {
            organization.setSt((String) attr.get("st").get());
        }
        if (attr.get("postalCode") != null) {
            organization.setPostalCode((String) attr.get("postalCode").get());
        }
        if (attr.get("businessCategory") != null) {
            organization.setBusinessCategory((String) attr.get("businessCategory").get());
        }
        return organization;
    }

}  
